﻿using System.ComponentModel.Composition;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.TextManager.Interop;
using Guids = Red.Scripts.Defines.Guids;

namespace Language.Utility
{
    [Export]
    internal class Settings
    {
        private IVsTextManager _textMgr;
        private LANGPREFERENCES _preferences;

        public bool IsBlockIndentationEnabled => _preferences.IndentStyle == vsIndentStyle.vsIndentStyleDefault;
        public bool IsSmartIndentationEnabled => _preferences.IndentStyle == vsIndentStyle.vsIndentStyleSmart;

        public bool IsTheNavigationBarEnabled => _preferences.fDropdownBar == 1;

        public Settings()
        {
            _textMgr = (IVsTextManager)Package.GetGlobalService( typeof( SVsTextManager ) );
        }

        public void Refresh()
        {
            var langPrefs = new LANGPREFERENCES[ 1 ];
            langPrefs[ 0 ].guidLang = Guids.Language.Id.Guid;
            _textMgr.GetUserPreferences( null, null, langPrefs, null );
            _preferences = langPrefs[ 0 ];
        }
    }
}
